<pre class="code">
<span class="srcline"><span class="lineno"><a href="7,1" id="srcline1"> 1</a></span><span class="line"><span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,2" id="srcline2"> 2</a></span><span class="line"><span class="comment">% RPI-MATLAB-Simulator</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,3" id="srcline3"> 3</a></span><span class="line"><span class="comment">% http://code.google.com/p/rpi-matlab-simulator/</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,4" id="srcline4"> 4</a></span><span class="line"><span class="comment">%</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,5" id="srcline5"> 5</a></span><span class="line"><span class="comment">% Creates a Simulator struct containing simulation properties</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,6" id="srcline6"> 6</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,7" id="srcline7"> 7</a></span><span class="line"><span class="keyword">function</span> <span class="var type1" id="S2T6U3">sim</span> = Simulator(<span class="var type1" id="S3T5U6">varargin</span>)</span></span>
<span class="srcline"><span class="lineno"><a href="7,8" id="srcline8"> 8</a></span><span class="line">    <span class="comment">%#codegen</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,9" id="srcline9"> 9</a></span><span class="line"> </span></span>
<span class="srcline"><span class="lineno"><a href="7,10" id="srcline10">10</a></span><span class="line">    <span class="comment">% The simulator struct</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,11" id="srcline11">11</a></span><span class="line">    <span class="comment">%sim = struct(); </span></span></span>
<span class="srcline"><span class="lineno"><a href="7,12" id="srcline12">12</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,13" id="srcline13">13</a></span><span class="line">    <span class="comment">% Simulator properties</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,14" id="srcline14">14</a></span><span class="line">    <span class="mxinfo" id="T1:U3"><span class="mxinfo" id="T1:U4"><span class="var type1" id="S2T6U10">sim</span>.time</span> = <span class="mxinfo" id="T1:U6">0</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,15" id="srcline15">15</a></span><span class="line">    <span class="mxinfo" id="T1:U7"><span class="mxinfo" id="T1:U8"><span class="var type1" id="S2T6U16">sim</span>.step</span> = <span class="mxinfo" id="T1:U10">0</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,16" id="srcline16">16</a></span><span class="line">    <span class="mxinfo" id="T1:U11"><span class="mxinfo" id="T1:U12"><span class="var type1" id="S2T6U22">sim</span>.MAX_STEP</span> = <span class="mxinfo" id="T1:U14"><span class="mxinfo" id="T1:U15">10</span>^9</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,17" id="srcline17">17</a></span><span class="line">    <span class="mxinfo" id="T4:U16"><span class="mxinfo" id="T4:U17"><span class="var type1" id="S2T6U30">sim</span>.gravity</span> = <span class="mxinfo" id="T4:U19">true</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,18" id="srcline18">18</a></span><span class="line">    <span class="mxinfo" id="T7:U20"><span class="mxinfo" id="T7:U21"><span class="var type1" id="S2T6U37">sim</span>.gravityVector</span> = <span class="mxinfo" id="T7:U23">[<span class="mxinfo" id="T1:U24">0</span>; <span class="mxinfo" id="T1:U25">0</span>; <span class="mxinfo" id="T1:U26">-<span class="mxinfo" id="T1:U27">9.81</span></span>]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,19" id="srcline19">19</a></span><span class="line">    <span class="mxinfo" id="T4:U28"><span class="mxinfo" id="T4:U29"><span class="var type1" id="S2T6U50">sim</span>.jointCorrection</span> = <span class="mxinfo" id="T4:U31">false</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,20" id="srcline20">20</a></span><span class="line">    <span class="mxinfo" id="T4:U32"><span class="mxinfo" id="T4:U33"><span class="var type1" id="S2T6U57">sim</span>.record</span> = <span class="mxinfo" id="T4:U35">false</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,21" id="srcline21">21</a></span><span class="line">    <span class="mxinfo" id="T8:U36"><span class="mxinfo" id="T8:U37"><span class="var type1" id="S2T6U64">sim</span>.record_directory</span> = <span class="mxinfo" id="T8:U39"><span class="string">''</span></span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,22" id="srcline22">22</a></span><span class="line">    <span class="mxinfo" id="T1:U40"><span class="mxinfo" id="T1:U41"><span class="var type1" id="S2T6U70">sim</span>.record_fileID</span> = <span class="mxinfo" id="T1:U43">-<span class="mxinfo" id="T1:U44">1</span></span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,23" id="srcline23">23</a></span><span class="line">    <span class="mxinfo" id="T4:U45"><span class="mxinfo" id="T4:U46"><span class="var type1" id="S2T6U77">sim</span>.FRICTION</span> = <span class="mxinfo" id="T4:U48">true</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,24" id="srcline24">24</a></span><span class="line">    <span class="mxinfo" id="T1:U49"><span class="mxinfo" id="T1:U50"><span class="var type1" id="S2T6U84">sim</span>.num_fricdirs</span> = <span class="mxinfo" id="T1:U52">7</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,25" id="srcline25">25</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,26" id="srcline26">26</a></span><span class="line">    <span class="mxinfo" id="T9:U53"><span class="mxinfo" id="T9:U54"><span class="var type1" id="S2T6U90">sim</span>.userFunction</span> = <span class="mxinfo" id="T9:U56">[]</span></span>;      <span class="comment">% A function handle to a user function</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,27" id="srcline27">27</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,28" id="srcline28">28</a></span><span class="line">    <span class="comment">%sim.userData = struct;      % A struct for storing user data</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,29" id="srcline29">29</a></span><span class="line">  </span></span>
<span class="srcline"><span class="lineno"><a href="7,30" id="srcline30">30</a></span><span class="line">    <span class="comment">% Body properties</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,31" id="srcline31">31</a></span><span class="line">    <span class="mxinfo" id="T1:U57"><span class="mxinfo" id="T1:U58"><span class="var type1" id="S2T6U97">sim</span>.num_bodies</span> = <span class="mxinfo" id="T1:U60">0</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,32" id="srcline32">32</a></span><span class="line">    <span class="mxinfo" id="T9:U61"><span class="mxinfo" id="T9:U62"><span class="var type1" id="S2T6U103">sim</span>.bodies</span> = <span class="mxinfo" id="T9:U64">[]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,33" id="srcline33">33</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,34" id="srcline34">34</a></span><span class="line">    <span class="comment">% Function handles</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,35" id="srcline35">35</a></span><span class="line">    <span class="comment">%sim.H_collision_detection = @collision_detection; </span></span></span>
<span class="srcline"><span class="lineno"><a href="7,36" id="srcline36">36</a></span><span class="line">    <span class="comment">%sim.H_dynamics = @LCPdynamics;</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,37" id="srcline37">37</a></span><span class="line">    <span class="comment">%sim.H_solver = @pathsolver; </span></span></span>
<span class="srcline"><span class="lineno"><a href="7,38" id="srcline38">38</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,39" id="srcline39">39</a></span><span class="line">    <span class="comment">% Use PATH's courtesy license if one isn't set already.</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,40" id="srcline40">40</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,41" id="srcline41">41</a></span><span class="line"><span class="comment">%     if isempty(getenv('PATH_LICENSE_STRING'))</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,42" id="srcline42">42</a></span><span class="line"><span class="comment">%         setenv('PATH_LICENSE_STRING','2069810742&amp;Courtesy_License&amp;&amp;&amp;USR&amp;2013&amp;14_12_2011&amp;1000&amp;PATH&amp;GEN&amp;31_12_2013&amp;0_0_0&amp;0&amp;0_0');</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,43" id="srcline43">43</a></span><span class="line"><span class="comment">%     end</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,44" id="srcline44">44</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,45" id="srcline45">45</a></span><span class="line">    <span class="comment">%sim.dynamics = struct;</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,46" id="srcline46">46</a></span><span class="line">    <span class="mxinfo" id="T9:U65"><span class="mxinfo" id="T9:U66"><span class="var type1" id="S2T6U110">sim</span>.contacts</span> = <span class="mxinfo" id="T9:U68">[]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,47" id="srcline47">47</a></span><span class="line">    <span class="mxinfo" id="T9:U69"><span class="mxinfo" id="T9:U70"><span class="var type1" id="S2T6U117">sim</span>.joints</span> = <span class="mxinfo" id="T9:U72">[]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,48" id="srcline48">48</a></span><span class="line">    <span class="mxinfo" id="T1:U73"><span class="mxinfo" id="T1:U74"><span class="var type1" id="S2T6U124">sim</span>.num_jointConstraints</span> = <span class="mxinfo" id="T1:U76">0</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,49" id="srcline49">49</a></span><span class="line">    <span class="mxinfo" id="T1:U77"><span class="mxinfo" id="T1:U78"><span class="var type1" id="S2T6U130">sim</span>.num_activeJointBodies</span> = <span class="mxinfo" id="T1:U80">0</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,50" id="srcline50">50</a></span><span class="line">    <span class="mxinfo" id="T1:U81"><span class="mxinfo" id="T1:U82"><span class="var type1" id="S2T6U136">sim</span>.num_activeBodies</span> = <span class="mxinfo" id="T1:U84">0</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,51" id="srcline51">51</a></span><span class="line">    <span class="mxinfo" id="T1:U85"><span class="mxinfo" id="T1:U86"><span class="var type1" id="S2T6U142">sim</span>.num_dynamicBodies</span> = <span class="mxinfo" id="T1:U88">0</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,52" id="srcline52">52</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,53" id="srcline53">53</a></span><span class="line">    <span class="comment">% Store solution error</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,54" id="srcline54">54</a></span><span class="line">    <span class="mxinfo" id="T9:U89"><span class="mxinfo" id="T9:U90"><span class="var type1" id="S2T6U148">sim</span>.solution_error</span> = <span class="mxinfo" id="T9:U92">[]</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,55" id="srcline55">55</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,56" id="srcline56">56</a></span><span class="line">    <span class="comment">% Collision detection properties</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,57" id="srcline57">57</a></span><span class="line">    <span class="mxinfo" id="T1:U93"><span class="mxinfo" id="T1:U94"><span class="var type1" id="S2T6U155">sim</span>.epsilon</span> = <span class="mxinfo" id="T1:U96">0.05</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,58" id="srcline58">58</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,59" id="srcline59">59</a></span><span class="line">    <span class="comment">% Graphics properties</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,60" id="srcline60">60</a></span><span class="line">    <span class="mxinfo" id="T1:U97"><span class="mxinfo" id="T1:U98"><span class="var type1" id="S2T6U161">sim</span>.figure</span> = <span class="mxinfo" id="T1:U100">1</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="7,61" id="srcline61">61</a></span><span class="line">    <span class="mxinfo" id="T4:U101"><span class="mxinfo" id="T4:U102"><span class="var type1" id="S2T6U167">sim</span>.draw</span> = <span class="mxinfo" id="T4:U104">true</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,62" id="srcline62">62</a></span><span class="line">    <span class="mxinfo" id="T4:U105"><span class="mxinfo" id="T4:U106"><span class="var type1" id="S2T6U174">sim</span>.drawContacts</span> = <span class="mxinfo" id="T4:U108">false</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,63" id="srcline63">63</a></span><span class="line">    <span class="mxinfo" id="T4:U109"><span class="mxinfo" id="T4:U110"><span class="var type1" id="S2T6U181">sim</span>.drawBoundingBoxes</span> = <span class="mxinfo" id="T4:U112">false</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,64" id="srcline64">64</a></span><span class="line">    <span class="mxinfo" id="T4:U113"><span class="mxinfo" id="T4:U114"><span class="var type1" id="S2T6U188">sim</span>.drawJoints</span> = <span class="mxinfo" id="T4:U116">false</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,65" id="srcline65">65</a></span><span class="line">    <span class="mxinfo" id="T9:U117"><span class="mxinfo" id="T9:U118"><span class="var type1" id="S2T6U195">sim</span>.contactGraphics</span> = <span class="mxinfo" id="T9:U120">[]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,66" id="srcline66">66</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,67" id="srcline67">67</a></span><span class="line">    <span class="comment">%% Parse input arguments</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,68" id="srcline68">68</a></span><span class="line">    <span class="keyword">if</span> nargin == 0</span></span>
<span class="srcline"><span class="lineno"><a href="7,69" id="srcline69">69</a></span><span class="line">        <span class="var type2" id="S2T0U208">sim</span>.h = 0.01;   <span class="comment">% Timestep size in seconds</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,70" id="srcline70">70</a></span><span class="line">    <span class="keyword">else</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,71" id="srcline71">71</a></span><span class="line">        <span class="mxinfo" id="T1:U121"><span class="mxinfo" id="T1:U122"><span class="var type1" id="S2T6U215">sim</span>.h</span> = <span class="mxinfo" id="T1:U124"><span class="var type1" id="S3T5U218">varargin</span>{1}</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="7,72" id="srcline72">72</a></span><span class="line">    <span class="keyword">end</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,73" id="srcline73">73</a></span><span class="line">    </span></span>
<span class="srcline"><span class="lineno"><a href="7,74" id="srcline74">74</a></span><span class="line"><span class="keyword">end</span></span></span>
<span class="srcline"><span class="lineno"><a href="7,75" id="srcline75">75</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,76" id="srcline76">76</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="7,77" id="srcline77">77</a></span><span class="line"></span></span>
</pre>
